/*! \file functions.h
 *  \brief A simple list for storing functions 
 *  \author Lluis Garrido
 *
 *  This file contains the structures necessary for
 *  storing an array of functions. 
 */

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#include "eval_expr.h"

/*! \def FUNCTION_ID_NONE
 *  \brief Reserved for identifying no function in field function_id of struct function.
 */
#define FUNCTION_ID_NONE          0

/*! \def MAX_ARGUMENTS
 *  \brief Maximum number of arguments that can be passed to a function. 
 */
#define MAX_ARGUMENTS      3 

/*! \struct function
 *  \brief A structure used to store functions.
 *
 *  A structure used to store functions. The structure stores, for each function
 *  - The name (a string) of the associated function
 *  - A unique identifier for the function (see ::list_functions_register_function1, ::list_functions_get_function_id)
 *  - The number of arguments the function admits
 *  - A function pointer to the function that evaluates the function
 *
 */

struct function
{
  unsigned int function_id; /*!< A unique identifier for the function */
  char name[MAX_SIZE_FUNCTION];  /*!< The name of the function */
  unsigned int nargs;       /*!< The number of arguments of the function */

  /*! \union funcpointer
   *  \brief A function pointer to the function that evaluates the function
   *
   *  A function pointer to the function that evaluates the function. f1
   *  is associated to a function that admits one argument, f2 to a function
   *  that admits two arguments, and f3 to a function that admits 3 arguments 
   */

  union funcpointer
  {
    double (*f1)(double);  /*!< If nargs is 1, this member stores the pointer to the function */
    double (*f2)(double, double); /*!< If nargs is 2, this member stores the pointer to the function */
    double (*f3)(double, double, double); /*!< If nargs is 3, this member stores the pointer to the function */
  } func;
};

/*! \struct list_functions
 *  \brief A structure to hold a list of functions.
 *
 *  The structure holds an array of struct function. In addition,
 *  the structure holds a member called currid. This member is 
 *  used to assign a unique identifier when registering new
 *  functions to the list.
 */

struct list_functions
{
  int nitems;
  int currid;
  struct function *el;
};

#endif
